* Replication file for "Issue Ownership Cues and Candidate Support"
* Kevin K. Banda

* Open the data
use "Replication data.dta", clear

/* Use the below code to install (first line) and/or load (second line) the plot style used in this paper:
ssc install blindschemes
set scheme plottig
*/

/* Install ciplot if you don't already have it:
ssc install ciplot
*/

/* Note: the "lazylabels" variable allows me to save the difference in means/proportions
	of interest along with the appropriate confidence interval bounds for plotting.
*/
gen lazylabels = .
replace lazylabels = 1 in 1
replace lazylabels = 2 in 2
replace lazylabels = 3 in 3
label define lazylab 1 "In-party - control" 2 "Out-party - control" 3 "Out-party - in-party"
label values lazylabels lazylab

**************
* Main paper *
**************

* Figure 1: copartisans
* Evaluation difference in means tests
ttest kbeval if pidsame2==0 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes
ttest kbeval if pidsame2==0 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbeval if pidsame2==0 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Evaluation difference in means figure
gen codiff = .
replace codiff = 6.918126 in 1
replace codiff = -1.994615 in 2
replace codiff = -8.912741 in 3

gen codifflo = .
replace codifflo = 2.37954 in 1
replace codifflo = -6.573159 in 2
replace codifflo = -13.28695 in 3

gen codiffhi = .
replace codiffhi = 11.45671 in 1
replace codiffhi = 2.583929 in 2
replace codiffhi = -4.538535 in 3

twoway (scatter codiff lazylabels, msize(2)) ///
	(rcap codifflo codiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-15(5)15, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-15 15, lc(white) lp(solid)) title("Evaluations", size(large))

* Vote choice difference in proportions tests
prtest kbvote2 if pidsame2==0 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes
prtest kbvote2 if pidsame2==0 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==0 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Difference in proportions figure
gen covdiff = .
replace covdiff = 0.1129457 in 1
replace covdiff = -0.0167141 in 2
replace covdiff = -0.1296597 in 3

gen covdifflo = .
replace covdifflo = 0.022203 in 1
replace covdifflo = -0.109724 in 2
replace covdifflo = -0.2186167 in 3

gen covdiffhi = .
replace covdiffhi = 0.2036883 in 1
replace covdiffhi = 0.0762959 in 2
replace covdiffhi = -0.0407027 in 3

twoway (scatter covdiff lazylabels, msize(2)) ///
	(rcap covdifflo covdiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in proportions", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.3(.1).3, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.3 .3, lc(white) lp(solid)) title("Vote choice", size(large))

* Figure 2: opposing partisans
* Evaluation difference in means tests
ttest kbeval if pidsame2==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
ttest kbeval if pidsame2==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
ttest kbeval if pidsame2==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Evaluation difference in means figure
gen oppediff = .
replace oppediff = -1.009934 in 1
replace oppediff = 8.763504 in 2
replace oppediff = 9.773438 in 3

gen oppedifflo = .
replace oppedifflo = -5.693469 in 1
replace oppedifflo = 3.795697 in 2
replace oppedifflo = 4.730857 in 3

gen oppediffhi = .
replace oppediffhi = 3.673602 in 1
replace oppediffhi = 13.73131 in 2
replace oppediffhi = 14.81602 in 3

twoway (scatter oppediff lazylabels, msize(2)) ///
	(rcap oppedifflo oppediffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-15(5)15, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-15 15, lc(white) lp(solid)) title("Evaluations", size(large))

* Difference in proportions tests
prtest kbvote2 if pidsame2==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
prtest kbvote2 if pidsame2==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Difference in proportions figure
gen oppvdiff = .
replace oppvdiff = -0.0226602 in 1
replace oppvdiff = 0.194019 in 2
replace oppvdiff = 0.2166792 in 3

gen oppvdifflo = .
replace oppvdifflo = -0.1121054 in 1
replace oppvdifflo = 0.0970965 in 2
replace oppvdifflo = 0.1222494 in 3

gen oppvdiffhi = .
replace oppvdiffhi = 0.066785 in 1
replace oppvdiffhi = 0.2909416 in 2
replace oppvdiffhi = 0.311109 in 3

twoway (scatter oppvdiff lazylabels, msize(2)) ///
	(rcap oppvdifflo oppvdiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in proportions", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.3(.1).3, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.3 .3, lc(white) lp(solid)) title("Vote choice", size(large))

* Figure 3: independents
* Evaluation difference in means
ttest kbeval if pidsame2==2 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
ttest kbeval if pidsame2==2 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbeval if pidsame2==2 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // no

* Evaluation difference in means figure
gen nondiff = .
replace nondiff = 0.9509314 in 1
replace nondiff = 0.0219941 in 2
replace nondiff = -0.9289373 in 3

gen nondifflo = .
replace nondifflo = -6.178956 in 1
replace nondifflo = -7.004996 in 2
replace nondifflo = -7.266863 in 3

gen nondiffhi = .
replace nondiffhi = 8.080818 in 1
replace nondiffhi = 7.048984 in 2
replace nondiffhi = 5.408988 in 3

twoway (scatter nondiff lazylabels, msize(2)) ///
	(rcap nondifflo nondiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-15(5)15, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-15 15, lc(white) lp(solid)) title("Evaluations", size(large))

* Difference in proportions tests
prtest kbvote2 if pidsame2==2 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==2 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==2 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // no

* Difference in proportions figure
gen nonvdiff = .
replace nonvdiff = 0.1019991 in 1
replace nonvdiff = 0.1026393 in 2
replace nonvdiff = 0.0006402 in 3

gen nonvdifflo = .
replace nonvdifflo = -0.0339491 in 1
replace nonvdifflo = -0.0358678 in 2
replace nonvdifflo = -0.1376228 in 3

gen nonvdiffhi = .
replace nonvdiffhi = 0.2379473 in 1
replace nonvdiffhi = 0.2411464 in 2
replace nonvdiffhi = 0.1389032 in 3

twoway (scatter nonvdiff lazylabels, msize(2)) ///
	(rcap nonvdifflo nonvdiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in proportions", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.3(.1).3, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.3 .3, lc(white) lp(solid)) title("Vote choice", size(large))
	
* Figure 4: ideological assessments

* All participants
* Difference in means: all people
ttest kbideo2 if owntreat==1 | owntreat==2, by(owntreat) level(90) // yes
ttest kbideo2 if owntreat==1 | owntreat==3, by(owntreat) level(90) // yes
ttest kbideo2 if owntreat==2 | owntreat==3, by(owntreat) level(90) // yes

* All participants figure
gen idalldiff = .
replace idalldiff = 0.3805387 in 1
replace idalldiff = -0.4574479 in 2
replace idalldiff = -0.8379866 in 3

gen idalldifflo = .
replace idalldifflo = 0.1870272 in 1
replace idalldifflo = -0.652657 in 2
replace idalldifflo = -1.022652 in 3

gen idalldiffhi = .
replace idalldiffhi = 0.5740503 in 1
replace idalldiffhi = -0.2622388 in 2
replace idalldiffhi = -0.6533217 in 3

twoway (scatter idalldiff lazylabels, msize(2)) ///
	(rcap idalldifflo idalldiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-1.4(.4)1.4, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-1.4 1.4, lc(white) lp(solid)) title("All participants", size(large))

* Copartisans
* Difference in means: copartisans
ttest kbideo2 if pidsame2==0 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes
ttest kbideo2 if pidsame2==0 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
ttest kbideo2 if pidsame2==0 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Copartisans figure
gen idcodiff = .
replace idcodiff = 0.4654813 in 1
replace idcodiff = -0.4430947 in 2
replace idcodiff = -0.908576 in 3

gen idcodifflo = .
replace idcodifflo = 0.1548019 in 1
replace idcodifflo = -0.7440374 in 2
replace idcodifflo = -1.199516 in 3

gen idcodiffhi = .
replace idcodiffhi = 0.7761606 in 1
replace idcodiffhi = -0.1421519 in 2
replace idcodiffhi = -0.617636 in 3

twoway (scatter idcodiff lazylabels, msize(2)) ///
	(rcap idcodifflo idcodiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-1.4(.4)1.4, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-1.4 1.4, lc(white) lp(solid)) title("Copartisans", size(large))
	
* Opposing partisans
* Difference in means: opposing partisans
ttest kbideo2 if pidsame2==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
ttest kbideo2 if pidsame2==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
ttest kbideo2 if pidsame2==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Opposing partisans figure
gen idopdiff = .
replace idopdiff = 0.2212958 in 1
replace idopdiff = -0.7650559 in 2
replace idopdiff = -0.9863517 in 3

gen idopdifflo = .
replace idopdifflo = -0.0924716 in 1
replace idopdifflo = -1.096819 in 2
replace idopdifflo = -1.298601 in 3

gen idopdiffhi = .
replace idopdiffhi = 0.5350632 in 1
replace idopdiffhi = -0.4332925 in 2
replace idopdiffhi = -0.6741023 in 3

twoway (scatter idopdiff lazylabels, msize(2)) ///
	(rcap idopdifflo idopdiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-1.4(.4)1.4, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-1.4 1.4, lc(white) lp(solid)) title("Opposing partisans", size(large))

* Independents
* Difference in means: nonpartisans
ttest kbideo2 if pidsame2==2 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes
ttest kbideo2 if pidsame2==2 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbideo2 if pidsame2==2 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

* Nonpartisans figure
gen idnpdiff = .
replace idnpdiff = 0.6019991 in 1
replace idnpdiff = 0.1480938 in 2
replace idnpdiff = -0.4539052 in 3

gen idnpdifflo = .
replace idnpdifflo = 0.2315431 in 1
replace idnpdifflo = -0.2289396 in 2
replace idnpdifflo = -0.8003274 in 3

gen idnpdiffhi = .
replace idnpdiffhi = 0.9724551 in 1
replace idnpdiffhi = 0.5251273 in 2
replace idnpdiffhi = -0.1074831 in 3

twoway (scatter idnpdiff lazylabels, msize(2)) ///
	(rcap idnpdifflo idnpdiffhi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in means", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-1.4(.4)1.4, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-1.4 1.4, lc(white) lp(solid)) title("Independents", size(large))
	
	

* Table 1: Mediation by perceived distance

/* Install "sgmediation" if you don't already have it. It isn't online anymore, so 
I included it in these replication materials: sgmediation.ado is the program and
sgmediation.help is the help file. Use the "sysdir" command to find your "personal"
directory and place both the program and the help files there. For me, this was
C:\ado\personal
*/


* Evaluations
* Copartisans
sgmediation kbeval if owntreat!=3 & pidsame2==0, mv(distance) iv(intreat)
sgmediation kbeval if owntreat!=2 & pidsame2==0, mv(distance) iv(outtreat)
sgmediation kbeval if owntreat!=1 & pidsame2==0, mv(distance) iv(intreat)


* Opposing partisans
sgmediation kbeval if owntreat!=3 & pidsame2==1, mv(distance) iv(intreat)
sgmediation kbeval if owntreat!=2 & pidsame2==1, mv(distance) iv(outtreat)
sgmediation kbeval if owntreat!=1 & pidsame2==1, mv(distance) iv(intreat)


* Nonpartisans
sgmediation kbeval if owntreat!=3 & pidsame2==2, mv(distance) iv(intreat)
sgmediation kbeval if owntreat!=2 & pidsame2==2, mv(distance) iv(outtreat)
sgmediation kbeval if owntreat!=1 & pidsame2==2, mv(distance) iv(intreat)

* Vote choice
* Copartisans
sgmediation kbvote2 if owntreat!=3 & pidsame2==0, mv(distance) iv(intreat)
sgmediation kbvote2 if owntreat!=2 & pidsame2==0, mv(distance) iv(outtreat)
sgmediation kbvote2 if owntreat!=1 & pidsame2==0, mv(distance) iv(intreat)

* Opposing partisans
sgmediation kbvote2 if owntreat!=3 & pidsame2==1, mv(distance) iv(intreat)
sgmediation kbvote2 if owntreat!=2 & pidsame2==1, mv(distance) iv(outtreat)
sgmediation kbvote2 if owntreat!=1 & pidsame2==1, mv(distance) iv(intreat)

* Nonpartisans
sgmediation kbvote2 if owntreat!=3 & pidsame2==2, mv(distance) iv(intreat)
sgmediation kbvote2 if owntreat!=2 & pidsame2==2, mv(distance) iv(outtreat)
sgmediation kbvote2 if owntreat!=1 & pidsame2==2, mv(distance) iv(intreat)

*********************
* Appendix material *
*********************

* Table 1 summary stats
ta pid3
ta ideo3
ta woman
ta rwhite
ta rblack
ta rhispanic
ta rasian
ta rother
ta educ2
ta income
sum ageyr

* Table 2 treatment assignment by relative PID status
ta owntreat pidsame2, col
ta owntreat pidsame2, summarize(kbeval)
ta owntreat pidsame2, summarize(kbvote2)

* Figure 1: copartisans means
ciplot kbeval if pidsame2==0, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Mean evaluations", size(large)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 146", place(n)) text(0 5 "N = 151", place(n)) text(0 8 "N = 159", place(n))

ciplot kbvote2 if pidsame2==0, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share", size(large)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 146", place(n)) text(0 5 "N = 151", place(n)) text(0 8 "N = 159", place(n))

* Figure 2: opposing partisans means
ciplot kbeval if pidsame2==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Mean evaluations", size(large)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 151", place(n)) text(0 5 "N = 166", place(n)) text(0 8 "N = 128", place(n))
	
ciplot kbvote2 if pidsame2==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share", size(large)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 151", place(n)) text(0 5 "N = 166", place(n)) text(0 8 "N = 128", place(n))

* Figure 3: independents means
ciplot kbeval if pidsame2==2, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Mean evaluations", size(large)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 62", place(n)) text(0 5 "N = 71", place(n)) text(0 8 "N = 66", place(n))

ciplot kbvote2 if pidsame2==2, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share", size(large)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 62", place(n)) text(0 5 "N = 71", place(n)) text(0 8 "N = 66", place(n))

* Figure 4: ideological assessments
* All participants
ciplot kbideo2, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(1(1)5) ytitle("Mean level of ideological congruence" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("All participants", size(large)) ///
	yline(1 5, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(1 2 "N = 359", place(n)) text(1 5 "N = 388", place(n)) text(1 8 "N = 353", place(n))

* Copartisans
ciplot kbideo2 if pidsame2==0, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(1(1)5) ytitle("Mean level of ideological congruence" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Copartisans", size(large)) ///
	yline(1 5, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(1 2 "N = 146", place(n)) text(1 5 "N = 151", place(n)) text(1 8 "N = 159", place(n))

* Opposing partisans
ciplot kbideo2 if pidsame2==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(1(1)5) ytitle("Mean level of ideological congruence" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Opposing partisans", size(large)) ///
	yline(1 5, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(1 2 "N = 151", place(n)) text(1 5 "N = 166", place(n)) text(1 8 "N = 128", place(n))

* Independents
ciplot kbideo2 if pidsame2==2, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(1(1)5) ytitle("Mean level of ideological congruence" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Independents", size(large)) ///
	yline(1 5, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(1 2 "N = 62", place(n)) text(1 5 "N = 71", place(n)) text(1 8 "N = 66", place(n))



* Figure 5: Evaluations among copartisans by PID group (Democrats and Republicans)
* Dems evaluate Dem candidate
ttest kbeval if pidsame2==0 & pid3==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes one tailed
ttest kbeval if pidsame2==0 & pid3==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbeval if pidsame2==0 & pid3==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

ciplot kbeval if pidsame2==0 & pid3==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) level(90) ///
	ylabel(, labsize(medium)) title("Democrats' mean evaluations of copartisans", size(medlarge)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 78", place(n)) text(0 5 "N = 93", place(n)) text(0 8 "N = 89", place(n))

gen dd1 = .
replace dd1 = 5.831679 in 1
replace dd1 = -3.097522 in 2
replace dd1 = -8.929201 in 3

gen dd1lo = .
replace dd1lo = 0.1305407 in 1
replace dd1lo = -9.506241 in 2
replace dd1lo = -14.75257 in 3

gen dd1hi = .
replace dd1hi = 11.53282 in 1
replace dd1hi = 3.311196 in 2
replace dd1hi = -3.10583 in 3

twoway (scatter dd1 lazylabels, msize(2)) ///
	(rcap dd1lo dd1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in evaluations", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-20(5)20, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-20 20, lc(white) lp(solid)) title("Difference in means (Democrats)", size(medlarge))

* Dems vote for Dem candidates
prtest kbvote2 if pidsame2==0 & pid3==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==0 & pid3==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==0 & pid3==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

ciplot kbvote2 if pidsame2==0 & pid3==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share: Democrats only", size(medlarge)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 78", place(n)) text(0 5 "N = 93", place(n)) text(0 8 "N = 89", place(n))

gen ddv1 = .
replace ddv1 = 0.1133168 in 1
replace ddv1 = -0.0472486 in 2
replace ddv1 = -0.1605654 in 3

gen ddv1lo = .
replace ddv1lo = -0.0086927 in 1
replace ddv1lo = -0.1742143 in 2
replace ddv1lo = -0.2786689 in 3

gen ddv1hi = .
replace ddv1hi = 0.2353262 in 1
replace ddv1hi = 0.0797171 in 2
replace ddv1hi = -0.042462 in 3

twoway (scatter ddv1 lazylabels, msize(2)) ///
	(rcap ddv1lo ddv1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in vote share", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.3(.1).3, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.3 .3, lc(white) lp(solid)) title("Difference in proportions (Democrats)", size(medlarge))

* Reps evaluate GOP candidate
ttest kbeval if pidsame2==0 & pid3==3 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // yes one tailed
ttest kbeval if pidsame2==0 & pid3==3 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbeval if pidsame2==0 & pid3==3 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

ciplot kbeval if pidsame2==0 & pid3==3, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Republicans' mean evaluations of copartisans", size(medlarge)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 68", place(n)) text(0 5 "N = 58", place(n)) text(0 8 "N = 70", place(n))

gen rr1 = .
replace rr1 = 8.308316 in 1
replace rr1 = -0.6882353 in 2
replace rr1 = -8.996552 in 3

gen rr1lo = .
replace rr1lo = 0.7674642 in 1
replace rr1lo = -7.289014 in 2
replace rr1lo = -15.73473 in 3

gen rr1hi = .
replace rr1hi = 15.84917 in 1
replace rr1hi = 5.912544 in 2
replace rr1hi = -2.258372 in 3

twoway (scatter rr1 lazylabels, msize(2)) ///
	(rcap rr1lo rr1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in evaluations", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-20(5)20, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-20 20, lc(white) lp(solid)) title("Difference in means (Republicans)", size(medlarge))

* Reps vote for GOP candidate
prtest kbvote2 if pidsame2==0 & pid3==3 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==0 & pid3==3 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==0 & pid3==3 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // no

ciplot kbvote2 if pidsame2==0 & pid3==3, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share: Republicans only", size(medlarge)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 68", place(n)) text(0 5 "N = 58", place(n)) text(0 8 "N = 70", place(n))

gen rrv1 = .
replace rrv1 = 0.1237323 in 1
replace rrv1 = -0.0252101 in 2
replace rrv1 = -0.0985222 in 3

gen rrv1lo = .
replace rrv1lo = -0.0116935 in 1
replace rrv1lo = 0.1099566 in 2
replace rrv1lo = -0.2320056 in 3

gen rrv1hi = .
replace rrv1hi = 0.259158 in 1
replace rrv1hi = -0.1603767 in 2
replace rrv1hi = 0.0349613 in 3

twoway (scatter rrv1 lazylabels, msize(2)) ///
	(rcap rrv1lo rrv1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in vote share", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.3(.1).3, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.3 .3, lc(white) lp(solid)) title("Difference in proportions (Republicans)", size(medlarge))


* Figure 6: Evaluations among opposing partisans by PID group (Democrats and Republicans)

* Dems evaluate GOP candidate
ttest kbeval if pidsame2==1 & pid3==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
ttest kbeval if pidsame2==1 & pid3==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
ttest kbeval if pidsame2==1 & pid3==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

ciplot kbeval if pidsame2==1 & pid3==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) level(90) ///
	ylabel(, labsize(medium)) title("Democrats' mean evaluations of" "opposing partisans", size(medlarge)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 94", place(n)) text(0 5 "N = 95", place(n)) text(0 8 "N = 71", place(n))

gen dr1 = .
replace dr1 = -0.8713326 in 1
replace dr1 = 14.99805 in 2
replace dr1 = 15.86938 in 3

gen dr1lo = .
replace dr1lo = -6.766216 in 1
replace dr1lo = 8.748624 in 2
replace dr1lo = 9.404179 in 3

gen dr1hi = .
replace dr1hi = 5.023551 in 1
replace dr1hi = 21.24748 in 2
replace dr1hi = 22.33459 in 3

twoway (scatter dr1 lazylabels, msize(2)) ///
	(rcap dr1lo dr1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in evaluations", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-25(5)25, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-25 25, lc(white) lp(solid)) title("Difference in means (Democrats)", size(medlarge))

* Dems vote for GOP candidate
prtest kbvote2 if pidsame2==1 & pid3==1 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==1 & pid3==1 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // yes
prtest kbvote2 if pidsame2==1 & pid3==1 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // yes

ciplot kbvote2 if pidsame2==1 & pid3==1, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share: Democrats only", size(medlarge)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 94", place(n)) text(0 5 "N = 95", place(n)) text(0 8 "N = 71", place(n))

gen drv1 = .
replace drv1 = -0.0668533 in 1
replace drv1 = 0.310908 in 2
replace drv1 = 0.3777613 in 3

gen drv1lo = .
replace drv1lo = -0.1779877 in 1
replace drv1lo = 0.1880911 in 2
replace drv1lo = 0.2580928 in 3

gen drv1hi = .
replace drv1hi = 0.0442811 in 1
replace drv1hi = 0.4337249 in 2
replace drv1hi = 0.4974298 in 3

twoway (scatter drv1 lazylabels, msize(2)) ///
	(rcap drv1lo drv1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in vote share", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.5(.1).5, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.5 .5, lc(white) lp(solid)) title("Difference in proportions (Democrats)", size(medlarge))
	
* Reps evaluate Dem candidate
ttest kbeval if pidsame2==1 & pid3==3 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
ttest kbeval if pidsame2==1 & pid3==3 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
ttest kbeval if pidsame2==1 & pid3==3 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // no

ciplot kbeval if pidsame2==1 & pid3==3, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") ///
	ylabel(0(10)70) ytitle("Mean" " ", size(medium)) level(90) ///
	ylabel(, labsize(medium)) title("Republicans' mean evaluations of" "opposing partisans", size(medlarge)) ///
	yline(0 70, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 57", place(n)) text(0 5 "N = 71", place(n)) text(0 8 "N = 57", place(n))

gen rd1 = .
replace rd1 = -1.734618 in 1
replace rd1 = 0.2982456 in 2
replace rd1 = 2.032864 in 3

gen rd1lo = .
replace rd1lo = -9.48198 in 1
replace rd1lo = -7.783994 in 2
replace rd1lo = -5.908303 in 3

gen rd1hi = .
replace rd1hi = 6.012744 in 1
replace rd1hi = 8.380485 in 2
replace rd1hi = 9.974031 in 3

twoway (scatter rd1 lazylabels, msize(2)) ///
	(rcap rd1lo rd1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in evaluations", size(med)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-25(5)25, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-25 25, lc(white) lp(solid)) title("Difference in means (Republicans)", size(medlarge))

* Reps vote for Dem candidate
prtest kbvote2 if pidsame2==1 & pid3==3 & (owntreat==1 | owntreat==2), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==1 & pid3==3 & (owntreat==1 | owntreat==3), by(owntreat) level(90) // no
prtest kbvote2 if pidsame2==1 & pid3==3 & (owntreat==2 | owntreat==3), by(owntreat) level(90) // no

ciplot kbvote2 if pidsame2==1 & pid3==3, by(owntreat) rcapopts(ls(2) lw(.8)) ///
	msize(2) ms(circle) mc(black) xsize(4) ysize(4) note("") level(90) ///
	ylabel(0(.1).8) ytitle("Proportion" " ", size(medium)) ///
	ylabel(, labsize(medium)) title("Vote share: Republicans only", size(medlarge)) ///
	yline(0 .8, lc(white) lp(solid)) xtitle("") xlabel(, labsize(medium)) ///
	text(0 2 "N = 57", place(n)) text(0 5 "N = 71", place(n)) text(0 8 "N = 57", place(n))

gen rdv1 = .
replace rdv1 = 0.0261922 in 1
replace rdv1 = 0.0350877 in 2
replace rdv1 = 0.0088955 in 3

gen rdv1lo = .
replace rdv1lo = -0.1192958 in 1
replace rdv1lo = -0.1182779 in 2
replace rdv1lo = -0.1370938 in 3

gen rdv1hi = .
replace rdv1hi = 0.1716803 in 1
replace rdv1hi = 0.1884533 in 2
replace rdv1hi = 0.1548847 in 3

twoway (scatter rdv1 lazylabels, msize(2)) ///
	(rcap rdv1lo rdv1hi lazylabels, legend(off) lc(black) ls(2) lw(.8)) ///
	, xsize(4) ysize(4) xtitle("") ytitle("Difference in vote share", size(med) height(-5)) ///
	xlabel(1 `" "In-party"  "vs control" "' 2 `" "Out-party"  "vs control" "' 3 `" "Out-party"  "vs in-party" "', labsize(med)) ///
	ylabel(-.5(.1).5, labsize(med)) xscale(range(0.8 3.2)) yline(0, lc(red)) ///
	yline(-.5 .5, lc(white) lp(solid)) title("Difference in proportions (Republicans)", size(medlarge))
